﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using Zxb.DayWork.Logic;
using System.Xml;

namespace Zxb.OneTimeWork
{
    public class StatDealerNoHit : BatchWorker
    {
        private string urlFormat = System.Configuration.ConfigurationManager.AppSettings["Tel400"];
        private string zxTelCode = System.Configuration.ConfigurationManager.AppSettings["Tel400zx"];
        private string jcTelCode = System.Configuration.ConfigurationManager.AppSettings["Tel400jc"];

        private DateTime enddate;
        private DateTime startdate;
        private ZxConstant zxconstant;

        private DataTable userDtZx;
        private DataTable userDtJc;
        private DataTable caseDtZxJc;
        private DataTable promotionDtZx;
        private DataTable promotionDtJc;
        private DataTable refreshDtZxJc;

        private DataTable reserveDtZx;

        private DataTable caseHitDtZxJc;
        private DataTable promotionHitDtZx;
        private DataTable pageHitDtZx;
        private DataTable userCaseMapDtZxJc;
        private DataTable userPromotionMapDtZx;
        private DataTable productDt;
        private DataTable priceDt;
        private DataTable dayHitNumJcDt;

        IEnumerable<StatDealerModel> zxUserList;
        IEnumerable<StatDealerModel> jcUserList;
        IEnumerable<StatDealerModel> zxDayCaseNum;
        IEnumerable<StatDealerModel> jcDayCaseNum;
        IEnumerable<StatDealerModel> zxDayProNum;
        IEnumerable<StatDealerModel> jcDayProNum;
        IEnumerable<StatDealerModel> zxDayReserveNum;

        IEnumerable<StatDealerModel> zxDayRefreshNum;
        IEnumerable<StatDealerModel> jcDayRefreshNum;
        IEnumerable<StatDealerModel> zxDayProductNum;
        IEnumerable<StatDealerModel> jcDayProductNum;
        IEnumerable<StatDealerModel> zxDayPriceNum;
        IEnumerable<StatDealerModel> jcDayPriceNum;
        IEnumerable<StatDealerModel> zxDayTelNum;
        IEnumerable<StatDealerModel> jcDayTelNum;

        DataTable targetDTzx;
        DataTable targetDTjc;

        public StatDealerNoHit()
        {
            startdate = TypeHelper.GetDay(DateTime.Today.AddDays(-1.0));
            enddate = startdate.AddDays(1.0);
            zxconstant = ZxConstantList.GetZxConstant(ZxJc.All);
        }
        //public StatDealerWorker(DateTime start, DateTime end, ZxJc z)
        //{
        //    startdate = start;
        //    enddate = end;
        //    zxconstant = ZxConstantList.GetZxConstant(z);
        //}
        public StatDealerNoHit(int lastNday)
        {
            if (lastNday > -1)
            {
                lastNday = -1;
            }
            startdate = TypeHelper.GetDay(DateTime.Now.AddDays(lastNday));
            enddate = startdate.AddDays(1.0);
            zxconstant = ZxConstantList.GetZxConstant(ZxJc.All);
        }

        private DataTable ZxUser()
        {
            string sql = "select u.ID,u.SoufunName,d.DealerName,u.CityName from UserDealerExtend d with(nolock) inner join [User] u with(nolock) on d.UserID=u.ID";
            return DAL.ReadDt_Retry_ReturnNewIfNull(DB.TaskReader, sql);
        }

        public DataTable CaseCount()
        {
            string sql = string.Format("select WeiKe_UserID,COUNT(1) as caseNum from Cases with(nolock) where AddedTime>='{0}' and AddedTime<'{1}' and IsValid=1 {2} group by WeiKe_UserID", startdate.ToShortDateString(), enddate.ToShortDateString(), zxconstant.whereCase);
            return DAL.ReadDt_Retry_ReturnNewIfNull(DB.TaskReader, sql);
        }

        public DataTable PromotionCount()
        {
            string sql = string.Format("select DesignerID,count(1) as proNum from CompanyNews with(nolock) where PublishDate>='{0}' and PublishDate<'{1}' and IsDel=0 {2} group by DesignerID"
            , startdate.ToShortDateString(), enddate.ToShortDateString(), zxconstant.wherePro);
            return DAL.ReadDt_Retry_ReturnNewIfNull(DB.TaskReader, sql);
        }

        public DataTable RefreshCount()
        {
            string sql = string.Format("select OperateUserID,COUNT(1) as refreshNum from opLog with(nolock) where RefreshTime>='{0}' and RefreshTime<'{1}' {2} group by OperateUserID"
            , startdate.ToShortDateString(), enddate.ToShortDateString(), zxconstant.whereRefresh);
            return DAL.ReadDt_Retry_ReturnNewIfNull(DB.ZxbReader, sql);
        }

        public DataTable zxReserveCount()
        {
            string sql = string.Format("select DealerID,COUNT(1) as reserveNum from DealerReservation with(nolock) where CreateTime>='{0}' and CreateTime<'{1}' group by DealerID"
            , startdate.ToShortDateString(), enddate.ToShortDateString());
            return DAL.ReadDt_Retry_ReturnNewIfNull(DB.TaskReader, sql);
        }

        public DataTable UserCaseMap()
        {
            string sql = "select CaseID,WeiKe_UserID from Cases with(nolock)";
            return DAL.ReadDt_Retry_ReturnNewIfNull(DB.TaskReader, sql);
        }
        public DataTable UserPromotionMap()
        {
            string sql = "select ID,DesignerID from CompanyNews with(nolock)";
            return DAL.ReadDt_Retry_ReturnNewIfNull(DB.TaskReader, sql);
        }

        public IEnumerable<StatDealerModel> TelCount(string telCode)
        {
            List<StatDealerModel> list = new List<StatDealerModel>();
            string url = string.Format(urlFormat, telCode, startdate.ToString("yyyy-MM-dd"));
            string txt = Net.GetStringFromUrl_Retry(url);
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(txt);

            XmlNodeList nodes = xmldoc.SelectNodes("result/homesoufun_400/common");
            foreach (XmlNode node in nodes)
            {
                int userid = TypeHelper.ParseInt(node.SelectSingleNode("ObjectID").InnerText);
                int num = TypeHelper.ParseInt(node.SelectSingleNode("PhoneNum").InnerText);
                list.Add(new StatDealerModel() { DealerID = userid, DayTelNum = num });
            }
            var query =
                from u in list
                group u by u.DealerID into g
                select new StatDealerModel
                {
                    DealerID = g.Key,
                    DayTelNum = g.Sum(x => x.DayTelNum)
                };
            return query;
        }

        private void GetCaseNumZxJc()
        {
            var query =
                from c in caseDtZxJc.AsEnumerable()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = TypeHelper.ParseInt(c.Field<object>("WeiKe_UserID")) > 0 ? 2 : 1,
                    DealerID = Math.Abs(TypeHelper.ParseInt(c.Field<object>("WeiKe_UserID"))),
                    DayCaseNum = TypeHelper.ParseInt(c.Field<object>("caseNum"))
                };
            zxDayCaseNum =
                from c in query
                where c.DealerType == 2
                select c;
            jcDayCaseNum =
                from c in query
                where c.DealerType == 1
                select c;
        }
        private void GetProNumZx()
        {
            zxDayProNum =
                from p in promotionDtZx.AsEnumerable()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 2,
                    DealerID = TypeHelper.ParseInt(p.Field<object>("DesignerID")),
                    DayProNum = TypeHelper.ParseInt(p.Field<object>("proNum"))
                };
        }
        private void GetProNumJc()
        {
            jcDayProNum =
                from p in promotionDtJc.AsEnumerable()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 1,
                    DealerID = TypeHelper.ParseInt(p.Field<object>("dealerId")),
                    DayProNum = TypeHelper.ParseInt(p.Field<object>("counts"))
                };
        }
        private void GetReserveNumZxJc()
        {
            zxDayReserveNum =
                from c in reserveDtZx.AsEnumerable()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 2,
                    DealerID = TypeHelper.ParseInt(c.Field<object>("DealerID")),
                    DayReserveNum = TypeHelper.ParseInt(c.Field<object>("reserveNum"))
                };
        }
        private void GetRefreshNumZxJc()
        {
            var query =
                from c in refreshDtZxJc.AsEnumerable()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = TypeHelper.ParseInt(c.Field<object>("OperateUserID")) > 400000 ? 1 : 2,
                    DealerID = TypeHelper.ParseInt(c.Field<object>("OperateUserID")),
                    DayRefreshNum = TypeHelper.ParseInt(c.Field<object>("refreshNum"))
                };
            zxDayRefreshNum =
                from c in query
                where c.DealerType == 2
                select c;
            var query2 =
                from c in query
                where c.DealerType == 1
                select c;
            jcDayRefreshNum =
                from c in query2
                join u in userDtJc.AsEnumerable()
                on c.DealerID equals u.Field<object>("UserID")
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 1,
                    DealerID = TypeHelper.ParseInt(u.Field<object>("DealerID")),
                    DayRefreshNum = c.DayRefreshNum
                };
        }
        private void GetProductNumZxJc()
        {
            var query =
                from c in productDt.AsEnumerable()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = TypeHelper.ParseInt(c.Field<object>("dealerId")) >= 0 ? 1 : 2,
                    DealerID = Math.Abs(TypeHelper.ParseInt(c.Field<object>("dealerId"))),
                    DayProductNum = TypeHelper.ParseInt(c.Field<object>("counts"))
                };
            zxDayProductNum =
                from c in query
                where c.DealerType == 2
                select c;
            jcDayProductNum =
                from c in query
                where c.DealerType == 1
                select c;
        }
        private void GetPriceNumZxJc()
        {
            var query =
                from c in priceDt.AsEnumerable()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = TypeHelper.ParseInt(c.Field<object>("dealerId")) >= 0 ? 1 : 2,
                    DealerID = Math.Abs(TypeHelper.ParseInt(c.Field<object>("dealerId"))),
                    DayPriceNum = TypeHelper.ParseInt(c.Field<object>("counts"))
                };
            zxDayPriceNum =
                from c in query
                where c.DealerType == 2
                select c;
            jcDayPriceNum =
                from c in query
                where c.DealerType == 1
                select c;
        }
        private void GetTelNumZxJc()
        {
            zxDayTelNum = TelCount(zxTelCode);
            jcDayTelNum = TelCount(jcTelCode);
        }
        private void GetUserListZxJc()
        {
            zxUserList =
                from c in userDtZx.AsEnumerable()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 2,
                    DealerID = TypeHelper.ParseInt(c.Field<object>("ID")),
                    CityName = c.Field<object>("CityName").ToString(),
                    DealerName = c.Field<object>("DealerName").ToString(),
                    UserName = c.Field<object>("SoufunName").ToString()
                };
            jcUserList =
                from c in userDtJc.AsEnumerable()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 1,
                    DealerID = TypeHelper.ParseInt(c.Field<object>("DealerID")),
                    CityName = c.Field<object>("CityName").ToString(),
                    DealerName = c.Field<object>("DealerName").ToString(),
                    UserName = c.Field<object>("UserName").ToString()
                };
        }

        protected override void ReadData()
        {
            caseDtZxJc = CaseCount();
            promotionDtZx = PromotionCount();
            refreshDtZxJc = RefreshCount();
            reserveDtZx = zxReserveCount();
            userDtZx = ZxUser();
            userDtJc = StatDealerWorkerJC.getJCDealer();
            productDt = StatDealerWorkerJC.getProductbyDate(startdate);
            priceDt = StatDealerWorkerJC.getCatalogProducts(startdate);
            promotionDtJc = StatDealerWorkerJC.getPromotionCount(startdate);
            dayHitNumJcDt = StatDealerWorkerJC.getHitsByDate(startdate);

            userCaseMapDtZxJc = UserCaseMap();
            userPromotionMapDtZx = UserPromotionMap();

            GetUserListZxJc();
            GetCaseNumZxJc();
            GetProNumZx();
            GetProNumJc();
            GetReserveNumZxJc();
            GetRefreshNumZxJc();
            GetProductNumZxJc();
            GetPriceNumZxJc();
            GetTelNumZxJc();
        }

        private void ProcessDealerZx()
        {
            var zx_User_Case =
                from u in zxUserList
                join c in zxDayCaseNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 2,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = (item == null) ? 0 : item.DayCaseNum

                };
            var zx_User_Case_Pro =
                from u in zx_User_Case
                join c in zxDayProNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 2,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = u.DayCaseNum,
                    DayProNum = (item == null) ? 0 : item.DayProNum
                };
            var zx_User_Case_Pro_Res =
                from u in zx_User_Case_Pro
                join c in zxDayReserveNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 2,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = u.DayCaseNum,
                    DayProNum = u.DayProNum,
                    DayReserveNum = (item == null) ? 0 : item.DayReserveNum
                };
            var zx_User_Case_Pro_Res_Ref =
                from u in zx_User_Case_Pro_Res
                join c in zxDayRefreshNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 2,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = u.DayCaseNum,
                    DayProNum = u.DayProNum,
                    DayReserveNum = u.DayReserveNum,
                    DayRefreshNum = (item == null) ? 0 : item.DayRefreshNum
                };
            var zx_User_Case_Pro_Res_Ref_Pdt =
                from u in zx_User_Case_Pro_Res_Ref
                join c in zxDayProductNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 2,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = u.DayCaseNum,
                    DayProNum = u.DayProNum,
                    DayReserveNum = u.DayReserveNum,
                    DayRefreshNum = u.DayRefreshNum,
                    DayProductNum = (item == null) ? 0 : item.DayProductNum
                };
            var zx_User_Case_Pro_Res_Ref_Pdt_Price =
                from u in zx_User_Case_Pro_Res_Ref_Pdt
                join c in zxDayPriceNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 2,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = u.DayCaseNum,
                    DayProNum = u.DayProNum,
                    DayReserveNum = u.DayReserveNum,
                    DayRefreshNum = u.DayRefreshNum,
                    DayProductNum = u.DayProductNum,
                    DayPriceNum = (item == null) ? 0 : item.DayPriceNum
                };

            var zx_User_Case_Pro_Res_Ref_Pdt_Price_HitZx_HitJc_Tel =
                from u in zx_User_Case_Pro_Res_Ref_Pdt_Price
                join c in zxDayTelNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 2,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = u.DayCaseNum,
                    DayProNum = u.DayProNum,
                    DayReserveNum = u.DayReserveNum,
                    DayRefreshNum = u.DayRefreshNum,
                    DayProductNum = u.DayProductNum,
                    DayPriceNum = u.DayPriceNum,
                    DayTelNum = (item == null) ? 0 : item.DayTelNum

                };
            var result =
                from z in zx_User_Case_Pro_Res_Ref_Pdt_Price_HitZx_HitJc_Tel
                where (z.DayCaseNum > 0 || z.DayProNum > 0 || z.DayRefreshNum > 0 || z.DayReserveNum > 0 || z.DayTelNum > 0
                || z.DayProductNum > 0 || z.DayPriceNum > 0 ) && z.DealerID != 0
                select z;

            targetDTzx = PrepareSchemaUdtStatDealer();

            foreach (var item in result)
            {
                DataRow row = targetDTzx.NewRow();
                row["StatDate"] = TypeHelper.GetDay(item.StatDate);
                row["DealerType"] = item.DealerType;
                row["DealerID"] = item.DealerID;
                row["DayCaseNum"] = item.DayCaseNum;
                row["DayProNum"] = item.DayProNum;
                row["DayProductNum"] = item.DayProductNum;
                row["DayPriceNum"] = item.DayPriceNum;
                row["DayRefreshNum"] = item.DayRefreshNum;
                row["DayReserveNum"] = item.DayReserveNum;
                row["DayTelNum"] = item.DayTelNum;

                row["CityName"] = item.CityName;
                row["DealerName"] = item.DealerName;
                row["UserName"] = item.UserName;

                targetDTzx.Rows.Add(row);
            }
        }
        private void ProcessDealerJc()
        {
            var jc_User_Case =
                from u in jcUserList
                join c in jcDayCaseNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 1,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = (item == null) ? 0 : item.DayCaseNum

                };
            var jc_User_Case_Pro =
                from u in jc_User_Case
                join c in jcDayProNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 1,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = u.DayCaseNum,
                    DayProNum = (item == null) ? 0 : item.DayProNum
                };

            var jc_User_Case_Pro_Res =
                from u in jc_User_Case_Pro
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 1,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = u.DayCaseNum,
                    DayProNum = u.DayProNum,
                    DayReserveNum = 0
                };
            var jc_User_Case_Pro_Res_Ref =
                from u in jc_User_Case_Pro_Res
                join c in jcDayRefreshNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 1,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = u.DayCaseNum,
                    DayProNum = u.DayProNum,
                    DayReserveNum = u.DayReserveNum,
                    DayRefreshNum = (item == null) ? 0 : item.DayRefreshNum
                };
            var jc_User_Case_Pro_Res_Ref_Pdt =
                from u in jc_User_Case_Pro_Res_Ref
                join c in jcDayProductNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 1,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = u.DayCaseNum,
                    DayProNum = u.DayProNum,
                    DayReserveNum = u.DayReserveNum,
                    DayRefreshNum = u.DayRefreshNum,
                    DayProductNum = (item == null) ? 0 : item.DayProductNum
                };
            var jc_User_Case_Pro_Res_Ref_Pdt_Price =
                from u in jc_User_Case_Pro_Res_Ref_Pdt
                join c in jcDayPriceNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 1,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = u.DayCaseNum,
                    DayProNum = u.DayProNum,
                    DayReserveNum = u.DayReserveNum,
                    DayRefreshNum = u.DayRefreshNum,
                    DayProductNum = u.DayProductNum,
                    DayPriceNum = (item == null) ? 0 : item.DayPriceNum
                };


            var jc_User_Case_Pro_Res_Ref_Pdt_Price_HitZx_HitJc_Tel =
                from u in jc_User_Case_Pro_Res_Ref_Pdt_Price
                join c in jcDayTelNum
                on u.DealerID equals c.DealerID into uc
                from item in uc.DefaultIfEmpty()
                select new StatDealerModel
                {
                    StatDate = startdate,
                    DealerType = 1,
                    DealerID = u.DealerID,
                    UserName = u.UserName,
                    CityName = u.CityName,
                    DealerName = u.DealerName,
                    DayCaseNum = u.DayCaseNum,
                    DayProNum = u.DayProNum,
                    DayReserveNum = u.DayReserveNum,
                    DayRefreshNum = u.DayRefreshNum,
                    DayProductNum = u.DayProductNum,
                    DayPriceNum = u.DayPriceNum,

                    DayTelNum = (item == null) ? 0 : item.DayTelNum

                };
            var result =
                from z in jc_User_Case_Pro_Res_Ref_Pdt_Price_HitZx_HitJc_Tel
                where (z.DayCaseNum > 0 || z.DayProNum > 0 || z.DayRefreshNum > 0 || z.DayReserveNum > 0 || z.DayTelNum > 0
                || z.DayProductNum > 0 || z.DayPriceNum > 0 ) && z.DealerID != 0
                select z;

            targetDTjc = PrepareSchemaUdtStatDealer();

            foreach (var item in result)
            {
                DataRow row = targetDTjc.NewRow();
                row["StatDate"] = TypeHelper.GetDay(item.StatDate);
                row["DealerType"] = item.DealerType;
                row["DealerID"] = item.DealerID;
                row["DayCaseNum"] = item.DayCaseNum;
                row["DayProNum"] = item.DayProNum;
                row["DayProductNum"] = item.DayProductNum;
                row["DayPriceNum"] = item.DayPriceNum;
                row["DayRefreshNum"] = item.DayRefreshNum;
                row["DayReserveNum"] = item.DayReserveNum;
                row["DayTelNum"] = item.DayTelNum;

                row["CityName"] = item.CityName;
                row["DealerName"] = item.DealerName;
                row["UserName"] = item.UserName;

                targetDTjc.Rows.Add(row);
            }
        }

        protected override void ProcessData()
        {
            ProcessDealerZx();
            ProcessDealerJc();
        }

        public static DataTable PrepareSchemaUdtStatDealer()
        {
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[]
            { 
                new DataColumn("StatDate",typeof(DateTime)),
                new DataColumn("DealerType",typeof(int)),
                new DataColumn("DealerID",typeof(int)),
                new DataColumn("DayCaseNum",typeof(int)),
                new DataColumn("DayProNum",typeof(int)),
                new DataColumn("DayProductNum",typeof(int)),
                new DataColumn("DayPriceNum",typeof(int)),
                new DataColumn("DayRefreshNum",typeof(int)),
                new DataColumn("DayReserveNum",typeof(int)),
                new DataColumn("DayHitNum",typeof(int)),
                new DataColumn("DayTelNum",typeof(int)),
                new DataColumn("CityName",typeof(string)),
                new DataColumn("DealerName",typeof(string)),
                new DataColumn("UserName",typeof(string)),
                new DataColumn("DayHitNumZx",typeof(int)),
                new DataColumn("DayHitNumJc",typeof(int))
            });
            return dt;
        }

        protected override void WriteData()
        {
            DAL.TVPUpdate_Retry_Split(targetDTzx, string.Concat("StatDealerInsertNoHit", startdate.ToString("MM")), "UdtStatDealer", "ZxbWriter");
            DAL.TVPUpdate_Retry_Split(targetDTjc, string.Concat("StatDealerInsertNoHit", startdate.ToString("MM")), "UdtStatDealer", "ZxbWriter");
            //DAL.TVPUpdate_Retry_Split(targetDTzx, string.Concat("StatDealerInsert", startdate.ToString("MM")), "UdtStatDealer", "ZxbWriter");
            //DAL.TVPUpdate_Retry_Split(targetDTjc, string.Concat("StatDealerInsert", startdate.ToString("MM")), "UdtStatDealer", "ZxbWriter");
        }
    }
}
